﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.IO;

namespace TestWin
{
    public partial class LogForm : Form
    {
        public LogForm()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            AppInfo.StrAcc =  this.text_Acc.Text;
            AppInfo.StrPass = this.text_Pass.Text;
            //"{\"status\":\"200\",\"reason\":\"login success!\",\"username\":\"test003\",\"access_token\":\"f287cd94e812b46299808e830c7e9d36\"}"
           String StrJson        = See51.CSharpSee51Sdk.Login51See(AppInfo.StrAcc, AppInfo.StrPass);
           String StrStatus      = See51.CSharpSee51Sdk.GetSimpleJsonFiled(StrJson, "status");
           AppInfo.StrAccessToken = See51.CSharpSee51Sdk.GetSimpleJsonFiled(StrJson, "access_token");

            String store = Application.StartupPath + "\\";
            See51.CSharpSee51Sdk.See51SDKSetFileStoreDir(store);
        
            if (StrStatus == "200")
            {
                String StrDevList  = See51.CSharpSee51Sdk.Get51SeeGroupDevs(0, AppInfo.StrAcc, AppInfo.StrAccessToken);

                String devinfos = See51.CSharpSee51Sdk.GetSimpleJsonFiled(StrDevList, "device_info");

                var arrdata = Newtonsoft.Json.Linq.JArray.Parse(devinfos);
                AppInfo.ListDevs = arrdata.ToObject<List<AppInfo.DevInfo>>();
                // string zone = jo["zone"].ToString();
                // string zone_en = jo["zone_en"].ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else {
                MessageBox.Show("登入错误");
            }
        }
    }
}
